﻿using MvcEntity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MvcApplication.service
{
    //操作角色
   public class DemoRoleService
    {

        public ResponseReslut addRole(RoleInfo request)
        {
            DateTime dateNow = DateTime.Now;
            using (var db = new DemoDbContext())
            {
                var dbrole= db.RoleInfo.Where(x => x.RoleName == request.RoleName).FirstOrDefault();
                if (!string.IsNullOrWhiteSpace(dbrole?.Id))
                {
                    MvcCommon.Log.Error($"处理角色业务错误：原因角色重复");
                    return CreateResponseReslut.CreateFail("角色重复");
                }
                request.Id = Guid.NewGuid().ToString().ToUpper();
                request.CreateDate = dateNow;
                request.EditDate = dateNow;
                db.RoleInfo.Add(request);
                db.SaveChanges();
                return CreateResponseReslut.CreateSuccess();
            }
        }
    }
}
